package com.rachel.liveplayer.activity;

import android.app.ActionBar;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.rachel.liveplayer.BaseActivity;
import com.rachel.liveplayer.R;
import com.rachel.utilslib.utils.StatusUtils;

public class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
    private static final String TAG = "zsr";
    /**
     * UI
     */
    private DrawerLayout mDrawerLayout;
    @Override
    public int getLayoutId() {
        return R.layout.activity_home;
    }

    @Override
    public void initView() {

        mDrawerLayout = getView(R.id.drawlayout);
        NavigationView navigationView = getView(R.id.navigation);
        navigationView.setNavigationItemSelectedListener(this);

        Toolbar toolbar = getView(R.id.toolbar);
        setSupportActionBar(toolbar);

        ActionBar actionBar = getActionBar();
        if (actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
        }
        ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.app_name,R.string.home);
        actionBarDrawerToggle.syncState();//联动

        //添加选装动画
        //mDrawerLayout.addDrawerListener(actionBarDrawerToggle);
    }

    @Override
    public void initData() {
        //透明状态栏
        StatusUtils.setStatusColor(this,getResources().getColor(R.color.maincolor));
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolbar_menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()){
            case R.id.menu_setting:
                Toast.makeText(this, getString(R.string.menu_setting), Toast.LENGTH_SHORT).show();
                 break;
            case R.id.menu_search :
                Toast.makeText(this, getString(R.string.menu_search), Toast.LENGTH_SHORT).show();
                break;

            default :
                break;
        
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {

        switch(item.getItemId()){
            case R.id.nav_home:
                Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
                 break;
            case R.id.nav_share :
                Toast.makeText(this, "share", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_aboutme :
                Toast.makeText(this, "AboutMe", Toast.LENGTH_SHORT).show();
                break;
            default :
                break;

        }
        return false;
    }
}
